﻿#include <QCoreApplication>
#include "Public.h"
#include "CSqlOper.h"
#include "CGlobal.h"
#include "CDevDataSensorSeries.h"
#include "windows.h"
#include "CSensorSeriesOper.h"

bool CSqlOper::initSql()
{
	bool bRet=m_pDbDllOper->initSql();
	m_pDbDllOper->startWork();
	QThread::msleep(2000);
	return bRet;
}

bool CSqlOper::selectDevInfo(QString& sDevGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_devinfo";
	cData.sSql = "select * from pai_sensor_series_devinfo where DEV_GUID=?";
	cData.addValue("DEV_GUID", sDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	vecRecord = cData.vecRecord;
	return bRet;
}

bool CSqlOper::insertDevInfo(QString& sDevGuid, QString& sDevName, QString& sSensorDevGuid, QString& sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_devinfo";
	cData.sSql = "insert into pai_sensor_series_devinfo (DEV_GUID,DEV_NAME,SENSOR_DEV_GUID)"
		" values(?,?,?)";

	cData.addValue("DEV_GUID", sDevGuid);
	cData.addValue("DEV_NAME", sDevName);
	cData.addValue("SENSOR_DEV_GUID", sSensorDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::deleteDevInfo(QString sDevId, QString& sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_devinfo";
	cData.sSql = "delete from pai_sensor_series_devinfo where DEV_GUID =?";
	cData.addValue("DEV_GUID", sDevId);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::selectSensorSeriesInfo(QString sDevGuid, CDevDataSensorSeries* pDevData, QString sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_config";
	cData.sSql = "select * from pai_sensor_series_config where DEVICE_GUID=?";
	cData.addValue("DEVICE_GUID", sDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	QVector<QSqlRecord> vecDataInfo = cData.vecRecord;
	for (int i = 0; i < vecDataInfo.size(); i++)
	{
		pDevData->m_sDevName = vecDataInfo[i].value("DEVICE_NAME").toString().trimmed();
		pDevData->m_sIp = vecDataInfo[i].value("DEVICE_IP").toString().trimmed();
		pDevData->m_sUserName = vecDataInfo[i].value("USER_NAME").toString().trimmed();
		pDevData->m_sPassWd = vecDataInfo[i].value("PASSWD").toString().trimmed();
		pDevData->m_sBeltName = vecDataInfo[i].value("BELT_NAME").toString().trimmed();
	}
	return bRet;
}

bool CSqlOper::selectSensorSeriesInfo(QString sDevGuid, QVector<QSqlRecord>& vecRecord, QString sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_config";
	cData.sSql = "select * from pai_sensor_series_config where DEVICE_GUID=?";
	cData.addValue("DEVICE_GUID", sDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	vecRecord = cData.vecRecord;
	return bRet;
}

bool CSqlOper::deleteSensorSeriesInfo(QString sDevGuid, QString sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_config";
	cData.sSql = "delete from pai_sensor_series_config where DEVICE_GUID =?";
	cData.addValue("DEVICE_GUID", sDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::insertDefDevCfg(QString sDevGuid,QString sDevName, QString sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_config";
	cData.sSql = "insert into pai_sensor_series_config (DEVICE_GUID,DEVICE_NAME,DEVICE_IP,USER_NAME,PASSWD,BELT_NAME)"
		" values(?,?,?,?,?,?)";

	cData.addValue("DEVICE_GUID", sDevGuid);
	cData.addValue("DEVICE_NAME", sDevName);
	cData.addValue("DEVICE_IP", "127.0.0.1");
	cData.addValue("USER_NAME", "admin");
	cData.addValue("PASSWD", "ky002380");
	cData.addValue("BELT_NAME", "");
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::selectSensorSeriesChannelInfo(QString sDevGuid, CDevDataSensorSeries* pDevData, QString sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_channel_config";
	cData.sSql = "select * from pai_sensor_series_channel_config where DEVICE_GUID=?";
	cData.addValue("DEVICE_GUID", sDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	QVector<QSqlRecord> vecDataInfo = cData.vecRecord;
	if (pDevData != nullptr)
	{
		for (int i = 0; i < vecDataInfo.size(); i++)
		{
			SChannel stChannel;
			stChannel.nChannelNo = vecDataInfo[i].value("CHANNEL_NO").toInt();
			stChannel.sChannelName = vecDataInfo[i].value("CHANNEL_NAME").toString().trimmed();
			stChannel.nIsEnable = vecDataInfo[i].value("IS_ENABLE").toInt();
			pDevData->m_mapChannel.insert(stChannel.nChannelNo, stChannel);
		}
	}
	return bRet;
}

bool CSqlOper::selectSensorSeriesChannelInfo(QString sDevGuid, QVector<QSqlRecord>& vecRecord, QString sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_channel_config";
	cData.sSql = "select * from pai_sensor_series_channel_config where DEVICE_GUID=?";
	cData.addValue("DEVICE_GUID", sDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	vecRecord = cData.vecRecord;
	return bRet;
}

bool CSqlOper::deleteChannelInfo(QString sDevGuid, QString sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_channel_config";
	cData.sSql = "delete from pai_sensor_series_channel_config where DEVICE_GUID=?";
	cData.addValue("DEVICE_GUID", sDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::insertDefChannelCfg(QString sDevGuid, QString sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	bool bRet = false;
	for (int i = 0; i < 8; i++)
	{
		CDatabaseExecData cData;
		cData.sTableName = "pai_sensor_series_channel_config";
		cData.sSql = "insert into pai_sensor_series_channel_config (DEVICE_GUID,CHANNEL_NO,CHANNEL_NAME,IS_ENABLE)"
			" values(?,?,?,?)";

		cData.addValue("DEVICE_GUID", sDevGuid);
		cData.addValue("CHANNEL_NO", i+1);
		cData.addValue("CHANNEL_NAME",A2T("通道%1").arg(i+1) );
		cData.addValue("IS_ENABLE", 1);
		bRet = m_pDbDllOper->exec(cData);
		sysSleep(50);
		sErrMsg = cData.sErr;
	}
	return bRet;
}

bool CSqlOper::selectChannelByDevGuid(QString sDevGuid, QVector<QSqlRecord>& vecRecord, QString &sMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_channel_config";
	cData.sSql = "select * from pai_sensor_series_channel_config where DEVICE_GUID=?";
	cData.addValue("DEVICE_GUID", sDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sMsg = cData.sErr;
	vecRecord = cData.vecRecord;
	return bRet;
}

bool CSqlOper::updateSensorSeries(QString sDevGuid, QString sName, QString sIP, QString sUser, QString sPassWd, QString sBeltName, QString &sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_config";
	cData.sSql = "update pai_sensor_series_config set DEVICE_NAME=?,DEVICE_IP=?, USER_NAME=?,PASSWD=?,BELT_NAME=? where DEVICE_GUID=?";
	cData.addValue("DEVICE_NAME", sName);
	cData.addValue("DEVICE_IP", sIP);
	cData.addValue("USER_NAME", sUser);
	cData.addValue("PASSWD", sPassWd);
	cData.addValue("BELT_NAME", sBeltName);
	cData.addValue("DEVICE_GUID", sDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::insertSensorSeries(QString sDevGuid, QString sName, QString sIP, QString sUser, QString sPassWd, QString sBeltName, QString &sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_config";
	cData.sSql = "insert into pai_sensor_series_config (DEVICE_GUID,DEVICE_NAME,DEVICE_IP,USER_NAME,PASSWD,BELT_NAME)"
		" values(?,?,?,?,?,?)";

	cData.addValue("DEVICE_GUID", sDevGuid);
	cData.addValue("DEVICE_NAME", sName);
	cData.addValue("DEVICE_IP", sIP);
	cData.addValue("USER_NAME", sUser);
	cData.addValue("PASSWD", sPassWd);
	cData.addValue("BELT_NAME", sBeltName);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::updateChannelInfo(QString sDevGuid, QVector<SChannel> vecChannel, QString &sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	bool bRet = false;
	for (int i = 0; i < vecChannel.size(); i++)
	{
		SChannel stChannel = vecChannel[i];
		CDatabaseExecData cData;
		cData.sTableName = "pai_sensor_series_channel_config";
		cData.sSql = "update pai_sensor_series_channel_config set CHANNEL_NAME=?,IS_ENABLE=? where DEVICE_GUID=? and CHANNEL_NO=?";
		cData.addValue("CHANNEL_NAME", stChannel.sChannelName);
		cData.addValue("IS_ENABLE", stChannel.nIsEnable);
		cData.addValue("DEVICE_GUID", sDevGuid);
		cData.addValue("CHANNEL_NO", stChannel.nChannelNo);
		bRet = m_pDbDllOper->exec(cData);
		sErrMsg = cData.sErr;
	}
	return bRet;
}

bool CSqlOper::insertChannelInfo(QString sDevGuid, QVector<SChannel> vecChannel, QString &sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	bool bRet = false;
	for (int i = 0; i < vecChannel.size(); i++)
	{
		CDatabaseExecData cData;
		cData.sTableName = "pai_sensor_series_channel_config";
		cData.sSql = "insert into pai_sensor_series_channel_config (DEVICE_GUID,CHANNEL_NO,CHANNEL_NAME,IS_ENABLE)"
			" values(?,?,?,?)";

		cData.addValue("DEVICE_GUID", sDevGuid);
		cData.addValue("CHANNEL_NO", vecChannel[i].nChannelNo);
		cData.addValue("CHANNEL_NAME", vecChannel[i].sChannelName);
		cData.addValue("IS_ENABLE", vecChannel[i].nIsEnable);
		bRet = m_pDbDllOper->exec(cData);
		sErrMsg = cData.sErr;
	}
	return bRet;
}

bool CSqlOper::insertSensorSeriesAlarm(SSensorSeriesAlarmInfo info, QString &sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_alarm_records";
	cData.sSql = "insert into pai_sensor_series_alarm_records (GUID,SCENE_GUID,DEV_GUID,DEV_NAME,CHANNEL_NO,ALARM_TIME,"
		"ACC_DIRECT,TEMP_ALARM,VIBRATION_ALARM,VOICE_ALARM,TEMP_VALUE,"
		"RMS,TIME_PEAK_TO_PEAK,ENV_PEAK_TO_PEAK,ENV_FAULT_FRQ_MULTI,ENV_BLADE_PASS_FRQ_MULTI,"
		"BLADE_PASSEDGE_FRQ_MULTI_SUM,TIME_DOMAIN_KURTOSIS,SHAPE_FACTOR,BELT_NAME,CHANNEL_NAME)"
		" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

	cData.addValue("GUID", info.sGuid);
	cData.addValue("SCENE_GUID", info.sSceneGuid);
	cData.addValue("DEV_GUID", info.sDevGuid);
	cData.addValue("DEV_NAME", info.sDevName);
	cData.addValue("CHANNEL_NO", info.nChannel);
	cData.addValue("ALARM_TIME", info.sAlarmTime);

	cData.addValue("ACC_DIRECT", info.sAccDirect);
	cData.addValue("TEMP_ALARM", info.nTempAlarm);
	cData.addValue("VIBRATION_ALARM", info.nVibrationAlarm);
	cData.addValue("VOICE_ALARM", info.nVoiceAlarm);
	cData.addValue("TEMP_VALUE", info.dTempValue);

	cData.addValue("RMS", info.dRMS);
	cData.addValue("TIME_PEAK_TO_PEAK", info.dTimePeakToPeak);
	cData.addValue("ENV_PEAK_TO_PEAK", info.dEnvPeakToPeak);
	cData.addValue("ENV_FAULT_FRQ_MULTI", info.dEnvFaultFrqMulti);
	cData.addValue("ENV_BLADE_PASS_FRQ_MULTI", info.dEnvBladePassFrqMulti);

	cData.addValue("BLADE_PASSEDGE_FRQ_MULTI_SUM", info.dBladePassEdgeFrqMultiSum);
	cData.addValue("TIME_DOMAIN_KURTOSIS", info.dTimeDomainKurtosis);
	cData.addValue("SHAPE_FACTOR", info.dShapeFactor);
	cData.addValue("BELT_NAME", info.sBeltName);
	cData.addValue("CHANNEL_NAME", info.sChannelName);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::selectSensorSeriesAlarm(QString sDevDuid, QString sStartTime, QString sEndTime, QVector<QSqlRecord>& vecRecord, QString &sMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_alarm_records";
	cData.sSql = "select * from pai_sensor_series_alarm_records where DEV_GUID=? and ALARM_TIME > '" + sStartTime + "' and ALARM_TIME < '" + sEndTime + "' order by ALARM_TIME desc";
	cData.addValue("DEV_GUID", sDevDuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sMsg = cData.sErr;
	vecRecord = cData.vecRecord;
	return bRet;
}

bool CSqlOper::selectHisData(QString sDevGuid, QString sStartTime, QString sEndTime, QVector<QSqlRecord>& vecRecord, QString &sMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_history";
	cData.sSql = "select * from pai_sensor_series_history where DEV_GUID=? and TIME > '" + sStartTime + "' and TIME < '" + sEndTime + "' order by TIME desc";
	cData.addValue("DEV_GUID", sDevGuid);
	bool bRet = m_pDbDllOper->exec(cData);
	sMsg = cData.sErr;
	vecRecord = cData.vecRecord;
	return bRet;
}

bool CSqlOper::selectHisData(QVector<QString> vecDevGuid, QString sStartTime, QString sEndTime, QVector<QSqlRecord>& vecRecord, QString &sMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_history";
	// 拼接 DEV_GUID 部分，形成 IN 子句
	QString devGuidInClause;
	for (int i = 0; i < vecDevGuid.size(); ++i)
	{
		devGuidInClause += "'" + vecDevGuid[i] + "'";
		if (i < vecDevGuid.size() - 1)
		{
			devGuidInClause += ", "; // 如果不是最后一个元素，添加逗号分隔
		}
	}
	// 构建 SQL 查询语句
	cData.sSql = "select * from pai_sensor_series_history where DEV_GUID IN (" + devGuidInClause + ") and TIME > '" + sStartTime + "' and TIME < '" + sEndTime + "' order by TIME desc";

	bool bRet = m_pDbDllOper->exec(cData);
	sMsg = cData.sErr;
	vecRecord = cData.vecRecord;
	return bRet;
}

bool CSqlOper::addSensorSeriesHistory(SSensorHisData& stData, QString sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_history";
	cData.sSql = "insert into pai_sensor_series_history (GUID,DEV_GUID,CHANNEL_NO,DATA_DIRECTION,RESULT,MATCH_LEVEL,TEMP_RESULT,RMS_RESULT,VOICE_RESULT,TIME,TEMP,"
		"RMS,RMS_FILE_URL,VOICE_FILE_URL,CHANNEL_NAME)"
		" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

	cData.addValue("GUID", stData.sGuid);
	cData.addValue("DEV_GUID", stData.sDevGuid);
	cData.addValue("CHANNEL_NO", stData.nChannelNo);
	cData.addValue("DATA_DIRECTION", stData.nDataDirection);
	cData.addValue("RESULT", stData.nResult);

	cData.addValue("MATCH_LEVEL", stData.nMatchLevel);
	cData.addValue("TEMP_RESULT", stData.nTempResult);
	cData.addValue("RMS_RESULT", stData.nRMSResult);
	cData.addValue("VOICE_RESULT", stData.nVoiceResult);
	cData.addValue("TIME", stData.sTime);

	cData.addValue("TEMP", stData.dTemp);
	cData.addValue("RMS", stData.dRMS);
	cData.addValue("RMS_FILE_URL", stData.sRMSFileUrl);
	cData.addValue("VOICE_FILE_URL", stData.sVoiceFileUrl);
	cData.addValue("CHANNEL_NAME", stData.sChannelName);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::selectTagID(QString& sDevGuid, QString& sTagID, QVector<QSqlRecord>& vecRecord, QString& sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "tag_config";
	cData.sSql = "select * from tag_config where DEV_GUID=? and TAG_ID=?";
	cData.addValue("DEV_GUID", sDevGuid);
	cData.addValue("TAG_ID", sTagID);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	vecRecord = cData.vecRecord;
	return bRet;
}

bool CSqlOper::insertTagID(QString& sDevGuid, QString& sTagID, QString& sTagAddr, QString& sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "tag_config";
	cData.sSql = "insert into tag_config (DEV_GUID,TAG_ID,TAG_ADDR)"
		" values(?,?,?)";

	cData.addValue("DEV_GUID", sDevGuid);
	cData.addValue("TAG_ID", sTagID);
	cData.addValue("TAG_ADDR", sTagAddr);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::updateTagID(QString& sDevGuid, QString& sTagID, QString& sTagAddr, QString& sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "tag_config";
	cData.sSql = "update tag_config set TAG_ADDR = ? where DEV_GUID = ? and TAG_ID = ?";

	cData.addValue("TAG_ADDR", sTagAddr);
	cData.addValue("DEV_GUID", sDevGuid);
	cData.addValue("TAG_ID", sTagID);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::selectResultLastTime(QVector<QSqlRecord>& vecRecord, QString sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "result_record";
	cData.sSql = "SELECT COALESCE(MAX(RESULT_TIME),NOW()) AS latest_time FROM result_record where RESULT_TYPE = 2;";
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	vecRecord = cData.vecRecord;
	return bRet;
}

bool CSqlOper::insertResult(QString sGuid, int nResultType, QString sResultName, QDateTime dTime, QString sPath, QString sHttpUrl, QString& sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "result_record";
	cData.sSql = "insert into result_record (GUID,RESULT_TYPE,RESULT_NAME,RESULT_TIME,RESULT_PATH,RESULT_PATH_URL)"
		" values(?,?,?,?,?,?)";

	cData.addValue("GUID", sGuid);
	cData.addValue("RESULT_TYPE", nResultType);
	cData.addValue("RESULT_NAME", sResultName);
	cData.addValue("RESULT_TIME", dTime);
	cData.addValue("RESULT_PATH", sPath);
	cData.addValue("RESULT_PATH_URL", sHttpUrl);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	return bRet;
}

bool CSqlOper::selectResult(QString sStartTime, QString sEndTime, QVector<QSqlRecord>& vecInfo, QString& sErrMsg)
{
	CDatabaseExecData cData;
	cData.sTableName = "result_record";
	cData.sSql = QString("select * from result_record where RESULT_TIME >= str_to_date('%1','%Y/%m/%d %T') and RESULT_TIME <= str_to_date('%2','%Y/%m/%d %T') and RESULT_TYPE=2 ")
		.arg(sStartTime)
		.arg(sEndTime);
	cData.sSql += "order by RESULT_TIME desc";
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	vecInfo = cData.vecRecord;
	return bRet;
}

bool CSqlOper::selSeseResultInfo(QVector<QSqlRecord>& vecRecordSese, QString sStartTime, QString sEndTime, QString& sErrMsg)
{
	QMutexLocker locker(m_pMutex);
	CDatabaseExecData cData;
	cData.sTableName = "pai_sensor_series_alarm_records";
	cData.sSql = "SELECT * FROM pai_sensor_series_alarm_records WHERE ALARM_TIME > ? AND ALARM_TIME <?  order by ALARM_TIME desc; ";
	cData.addValue("ALARM_TIME", sStartTime);
	cData.addValue("ALARM_TIME", sEndTime);
	bool bRet = m_pDbDllOper->exec(cData);
	sErrMsg = cData.sErr;
	vecRecordSese = cData.vecRecord;
	return bRet;
}

CSqlOper::CSqlOper()
{
	m_pMutex = new QMutex();
	//配置文件地址
	QString sFilePath = QCoreApplication::applicationDirPath() + "/DLL/SensorSeriesCfg/SensorSeriesCfg.xml";
	QString sDllPath = QCoreApplication::applicationDirPath() + "/SqlOper.dll";
	m_pDbDllOper = new CSqlDllOper(g_sTableName, sFilePath, sDllPath);
}

CSqlOper::~CSqlOper()
{
	delete m_pDbDllOper;
	m_pDbDllOper = nullptr;
}
